<?php

namespace mz\ars;

use Yii;

/**
 * This is the model class for table "{{%album}}".
 *
 * @property int $id 主键id
 * @property string $type 默认album 相册 图片来源（站内栏目） about关于我们  contact联系我们 
 * @property int $type_id 图片对应的素材id 
 * @property string $picture 相关图片 从相册表取图片地址
 * @property string $name 图片名称
 * @property string $desc 描述
 * @property int $uploaded 上传时间
 */
class Album extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%album}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['type_id', 'uploaded'], 'integer'],
            [['type', 'picture', 'name', 'desc'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'type' => 'Type',
            'type_id' => 'Type ID',
            'picture' => 'Picture',
            'name' => 'Name',
            'desc' => 'Desc',
            'uploaded' => 'Uploaded',
        ];
    }

    # 应用ID转图片地址
    # id 记录id
    # $type 记录类型
    public static function id2path($id,$type)
    {
        $list = self::find()->where(['type' => $type , 'type_id' => $id])->asArray()->all();
        if (empty($list))return '';

        array_walk($list,function($value){
            if (!empty($value['picture']))$value['picture'] = "http://img.mzcms.com/".$value['picture'];
        });
        return $list;
    }
}
